﻿
using Repositories.Interfaces;
using System.Linq;
using System.Linq.Expressions;
using System.Collections.Generic;
using System;
namespace Repositories.Implementations
{
    public class GroupMealRepository : BaseRepository<GroupMeal>, IGroupMealRepository
    {
        public GroupMealRepository()
            : base()
        {
        }
        /// <summary>
        /// Gets the name of the entity set.
        /// </summary>
        /// <value>The name of the entity set.</value>
        protected override string EntitySetName
        {
            get
            {
                return "ASE_DatabaseEntities.GroupMeal";
            }
        }

        public void Refresh()
        {
            ASEDbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, ASEDbContext.GroupMeal);
        }

        private IGroupMealRepository _GroupMealRepository;

        /// <summary>
        /// Gets the GroupMeal repository.
        /// </summary>
        /// <value>The GroupMeal repository.</value>
        public IGroupMealRepository GroupMealRep
        {
            get
            {
                if (_GroupMealRepository == null)
                {
                    _GroupMealRepository = DIHelper.Resolve<IGroupMealRepository>();
                }
                return _GroupMealRepository;
            }
        }




        /// <summary>
        /// Creates the GroupMeal.
        /// </summary>
        /// <param name="item">The item.</param>
        public void CreateGroupMeal(GroupMeal item)
        {
            GroupMealRep.Insert(item);
        }

        /// <summary>
        /// Queries the GroupMeal.
        /// </summary>
        /// <param name="predicate">The predicate.</param>
        /// <returns>Query results.</returns>
        public IQueryable<GroupMeal> QueryGroupMeal(Expression<Func<GroupMeal, bool>> predicate)
        {
            return GroupMealRep.GetQuery(predicate);
        }

        /// <summary>
        /// Finds the by ID.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns>The GroupMeal with input ID.</returns>
        public GroupMeal FindById(int id)
        {
            IQueryable<GroupMeal> returnValue = GroupMealRep.GetQuery(itm => itm.Id == id);
            if (returnValue.Count() == 0)
                return null;
            return returnValue.FirstOrDefault();
        }

        /// <summary>
        /// Gets all GroupMeal.
        /// </summary>
        /// <returns>all GroupMeal.</returns>
        public List<GroupMeal> GetAllGroupMeal()
        {
            IQueryable<GroupMeal> returnValue = GroupMealRep.GetQuery();
            if (returnValue.Count() == 0)
                return null;
            return returnValue.ToList();
        }


        /// <summary>
        /// Get All Category For DropDownList
        /// </summary>
        public List<Category> GetAllCategorysForDropDownList()
        {
            List<Category> listCategory = new List<Category>();

            return listCategory;
        }

        /// <summary>
        /// Get All Category For DropDownList
        /// </summary>
        public List<Category> GetAllCategoriesForDropDownList()
        {
            List<Category> listCategory = new List<Category>();

            return listCategory;
        }

        public List<GroupMeal> GetAllGroupMealByCategory(int categoryId)
        {
            IQueryable<GroupMeal> returnValue = GroupMealRep.GetQuery(itm => itm.Category.Id == categoryId);
            if (returnValue.Count() == 0)
                return null;
            foreach (var group in returnValue)
            {
                group.Meal.Load();
            }
            return returnValue.ToList();
        }

        /// <summary>
        /// Edits the GroupMeal.
        /// </summary>
        /// <param name="item">The item.</param>
        public void EditGroupMeal(GroupMeal item)
        {
            GroupMealRep.Update(item);
        }


        /// <summary>
        /// Deletes the GroupMeal.
        /// </summary>
        /// <param name="item">The item.</param>
        public void DeleteGroupMeal(GroupMeal item)
        {
            GroupMealRep.Delete(item);
        }


        /// <summary>
        /// Deattaches the specified category.
        /// </summary>
        /// <param name="category">The category.</param>
        public void Deattach(Category category)
        {

        }

        /// <summary>
        /// Deattaches the specified GroupMeal.
        /// </summary>
        /// <param name="solicitation">The GroupMeal.</param>
        public void DeattachTo(GroupMeal combo)
        {
            GroupMealRep.DeattachTo(combo);
        }

        /// <summary>
        /// Applies the changes to database.
        /// </summary>
        public void ApplyTheChanges()
        {
            GroupMealRep.UnitOfWork.SaveChanges();
        }

        /// <summary>
        /// Accepts all changes.
        /// </summary>
        public void AcceptAllChanges()
        {
            GroupMealRep.UnitOfWork.AcceptAllChanges();
        }


    }
}
